import wx

class Example(wx.Frame):
    
    def __init__(self, *args, **kw):
        super(Example, self).__init__(*args, **kw)
        self.BMI = 0.0
        self.pnl = wx.Panel(self)
        self.st=wx.StaticText(self.pnl, label='Body mass index', pos=(10, 30))
        self.wg = wx.StaticText(self.pnl, label = "weight", pos=(10, 70))
        self.hg = wx.StaticText(self.pnl, label = "height", pos=(10, 110))
        
        self.wg_in = wx.SpinCtrl(self.pnl, value = "50", pos = (150,70), min = 1, max = 1000)
        self.hg_in = wx.SpinCtrl(self.pnl, value = "50", pos = (150, 110), min = 1, max = 1000)
        self.com_btn = wx.Button(self.pnl, label='Compute', pos=(70, 150))
        
        self.cbtn = wx.Button(self.pnl, label='Close', pos=(150, 150))
        self.cbtn.Bind(wx.EVT_BUTTON, self.OnClose)
        
        #self.BMI = wg_in.GetValue() / (hg_in.GetValue() * hg_in.GetValue())
        self.com_btn.Bind(wx.EVT_BUTTON, self.Compute)
        self.bm = wx.StaticText(self.pnl, label = str(self.BMI), pos = (150, 30))
        self.weightSituation = wx.StaticText(self.pnl, label = "", pos = (115, 185))
        self.InitUI()
    def OnClose(self, e):
        self.Close(True)
    def Compute(self,e):
        delitel = self.hg_in.GetValue()/100
        self.BMI = self.wg_in.GetValue() / (delitel * delitel)
        self.BMI = round(self.BMI, 2)
        if self.BMI <= 18.5:
            self.weightSituation.SetLabel("underweight")
        elif self.BMI <= 24.9:
            self.weightSituation.SetLabel("normal weight")
        elif self.BMI <= 29.9:
            self.weightSituation.SetLabel("overweight")
        else:
            self.weightSituation.SetLabel("obese weight")
        self.bm.SetLabel(str(self.BMI))

        
        
    def InitUI(self):
        self.SetSize((300, 250))
        self.SetTitle('BMI')
        self.Centre()
        self.Show(True)

ex = wx.App()
Example(None)
ex.MainLoop() 